<?php

namespace app\admin\model\scanwork;

use think\Model;

class DailyWorkImage extends Model
{
    // 表名
    protected $name = 'scanwork_daily_work_image';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'createtime_text',
        'image_type_text'
    ];

    public function getImageTypeList()
    {
        return ['1' => __('员工上传'), '2' => __('管理员上传')];
    }

    public function getImageTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['image_type']) ? $data['image_type'] : '');
        $list = $this->getImageTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    // 关联工作项目
    public function workitem()
    {
        return $this->belongsTo('DailyWorkItem', 'work_item_id', 'id');
    }

    // 关联每日工作报工
    public function dailyworkreport()
    {
        return $this->belongsTo('DailyWorkReport', 'daily_report_id', 'id');
    }
}
